import shutil

import datetime
import os
import json
import re
import time
import sys
import hashlib


# 增加wechat_mp到sys.path
sys.path.append(r'J:\_ALL\CODE\gitee\yeahmao\wechat_mp')
sys.path.insert(0,  r'J:\_ALL\CODE\gitee\constellations\Capricorn')
from wechat_mp import WeChat
from _utils import *
from utils import *

rootSrc = r'J:\_ALL\_data\爬虫\公众号历史文章\cosplay二次元大全'
rootDst = r'J:\_ALL\LIFE\Wechat\文章发布\acg美女cosplay营地\top\md_all'


def 生成md内容(full_path, title):
    lst = os.listdir(full_path)
    ret = '\n## {}\n\n'.format(title)
    for filename_pic in lst:
        full_path_pic = os.path.join(full_path, filename_pic)
        ret += '![{}]({})\n\n'.format(full_path_pic, full_path_pic)

    return ret


def 规范化标题(title):
    prefixs = ['cos：', 'Cos：', 'COS：', 'cos；', 'co：', ]
    for pre in prefixs:
        if title.startswith(pre):
            return title[len(pre):]
    return title


def main():
    # _my_mp_name = '夜猫逐梦'
    # _my_mp_name = 'acg美女cosplay营地'
    _my_mp_name = 'cosplay二次元大全'
    最大个数 = 30
    current = 0

    lst = os.listdir(rootSrc)
    for filename in lst:
        full_path = os.path.join(rootSrc, filename)
        if not os.path.isdir(full_path):
            continue

        print(full_path)
        title = filename.split('--20')[0]
        title = 规范化标题(title)
        md全路径 = os.path.join(rootDst, my_str_convert_2_path(title) + '.md')
        if os.path.isfile(md全路径):
            continue

        md内容 = 生成md内容(full_path, title)
        print(title, md内容)
        with open(md全路径, 'w', encoding='utf-8') as wf:
            wf.write(md内容)

        current = current + 1
        if current >= 最大个数:
            return


if __name__ == "__main__":
    print("------------------    Enter __main__    ------------------")

    print(u"[Current work directory is : ]\t" + os.getcwd())
    print(u"[Current process ID is : ]\t" + str(os.getpid()))
    print("\n")
    main()

    print("------------------    Leave __main__    ------------------")
